package com.oswego.dawcs;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.HorizontalScrollView;

public class NonFocusingHorizontalScrollView extends HorizontalScrollView {
	
	public NonFocusingHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public NonFocusingHorizontalScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	// true if we can scroll (not locked)
    // false if we cannot scroll (locked)
    public static boolean mScrollable = true;

    public boolean isScrollable() {
        return mScrollable;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
//    	if(ev.getPointerCount()>1){
//    		mScrollable = true;
//    	} else {
//    		mScrollable = false;
//    	}
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // if we can scroll pass the event to the superclass
                if (mScrollable) return super.onTouchEvent(ev);
                // only continue to handle the touch event if scrolling enabled
                return mScrollable; // mScrollable is always false at this point
            default:
                return super.onTouchEvent(ev);
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
//    	if(ev.getPointerCount()>1){
//    		mScrollable = true;
//    	} else {
//    		mScrollable = false;
//    	}
    	
//    	System.out.println("mScrollable: " + mScrollable);
    	
        // Don't do anything with intercepted touch events if 
        // we are not scrollable
        if (!mScrollable) return false;
        else return super.onInterceptTouchEvent(ev);
    }

}
